<?php

namespace Modules\Api\Http\Controllers;

use HiCommon\Service\UsersCompanyService;
use HiCommon\Service\UsersVehicleService;
use HiCommon\Service\VehicleModelService;
use Illuminate\Support\Facades\Request;

class UsersVehicleController extends BaseController
{

    /**
     * 车型列表
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function vehicle_model_list(){
        try {
            $n_pid = intval(Request::input('pid'));
            $res = VehicleModelService::api_vehicle_model_list($n_pid);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 车型列表-顶级-new
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function vehicle_model_top_list(){
        try {
            $n_pid = intval(Request::input('pid'));
            $res = VehicleModelService::api_vehicle_model_top_list($n_pid);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 用户企业列表
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function my_company_list(){
        try {
            $n_uid = api_user_id();
            $res = UsersCompanyService::api_get_user_company_list($n_uid);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }

    }

    /**
     * 添加企业
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function add_company(){
        try {
            $n_uid = api_user_id();
            $arr_input = Request::input();

            shiwu_start();
            $res = UsersCompanyService::api_add_user_company($n_uid,$arr_input);
            shiwu_end($res);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 删除企业
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function del_company(){
        try {
            $n_uid = api_user_id();
            $n_id = Request::input('id',0);

            shiwu_start();
            $res = UsersCompanyService::api_del_user_company($n_id,$n_uid);
            shiwu_end($res);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 修改企业
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function edit_company(){
        try {
            $n_uid = api_user_id();
            $arr_input = Request::input();

            shiwu_start();
            $res = UsersCompanyService::api_edit_user_company($n_uid,$arr_input);
            shiwu_end($res);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 企业-车辆列表
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function company_vehicle_list(){
        try {
            $n_company_id = Request::input('company_id',0);
            $res = UsersCompanyService::api_company_vehicle_list($n_company_id);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 添加车辆-企业和非企业
     *
     * @return array|mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function add_user_vehicle(){
        try {
            $n_uid = api_user_id();
            $arr_input = Request::input();

            shiwu_start();
            $res = UsersVehicleService::api_add_whole_user_vehicle($n_uid,$arr_input);
            shiwu_end($res);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 修改车辆档案
     *
     * @return array|mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function edit_user_vehicle(){
        try {
            $n_uid = api_user_id();
            $arr_input = Request::input();

            shiwu_start();
            $res = UsersVehicleService::api_edit_whole_user_vehicle($n_uid,$arr_input);
            shiwu_end($res);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 设置用户默认车辆
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function set_default_user_vehicle(){
        try {
            $n_uid = api_user_id();
            $n_id = Request::input('id',0);

            shiwu_start();
            $res = UsersVehicleService::api_set_default_user_vehicle($n_id,$n_uid);
            shiwu_end($res);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }


    /**
     * 删除车辆
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function del_user_vehicle(){
        try {
            $n_uid = api_user_id();
            $n_id = Request::input('id',0);

            shiwu_start();
            $res = UsersVehicleService::api_del_user_vehicle($n_id,$n_uid);
            shiwu_end($res);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*我的车库*/
    public function my_user_vehicle(){
        try {
            $n_uid = api_user_id();
            $res = UsersVehicleService::api_my_user_vehicle($n_uid);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*我的车辆列表*/
    public function my_personal_vehicle_list(){
        try {
            $n_uid = api_user_id();
            $res = UsersVehicleService::api_user_vehicle_list($n_uid);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*首页进入车辆详情页*/
    public function my_vehicle_info(){
        try {
            $n_id = Request::input('id',0);
            $res = UsersVehicleService::api_vehicle_info($n_id);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*修改车辆基本信息*/
    public function edit_vehicle_basic(){
        try {
            $arr_input = Request::input();
            $res = UsersVehicleService::api_edit_vehicle_basic($arr_input);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*修改车辆 保险信息*/
    public function edit_vehicle_insurance_info(){
        try {
            $arr_input = Request::input();
            $res = UsersVehicleService::api_vehicle_insurance_info($arr_input);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /**
     * 首页进入车辆详情页-企业列表
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function my_vehicle_info_company_list(){
        try {
            $n_uid = api_user_id();
            $res = UsersCompanyService::api_get_index_company_list($n_uid);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }

    }

    /*用户车辆详情*/
    public function my_vehicle_detail(){
        try {
            $n_id = Request::input('id',0);
            $res = UsersVehicleService::api_vehicle_detail($n_id);
            return $res;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*用户默认车辆*/
    public function user_default_car(){
        try {
            $n_uid = intval(api_user_id());
            $result = UsersVehicleService::api_user_default_car($n_uid);
            return $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*企业车辆检测记录*/
    public function company_vehicle_check_record(){
        try {
//            $n_uid = intval(api_user_id());
            $n_company_id = intval(Request::input('id',0));
            $s_year_month = str_trim(Request::input('year_month',''));
            $result = UsersVehicleService::api_company_vehicle_check_records($n_company_id,$s_year_month);
            return $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

}